package se.liu.oschi129.game.objects;

import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.objects.WorldMovableObject;
import se.liu.oschi129.world.objects.WorldObject;

/**
 * This is a movable platform - a horizontal or/and a vertical speed can be set.
 * The player will move with the platform if the platform is below the player.
 * 
 * @author oschi129
 */
public class ObjectMovablePlatform extends WorldMovableObject {
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public ObjectMovablePlatform(double x, double y, double width, double height) {
		super(x, y, width, height);
		setType(Type.PLATFORM);
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	/** Moves the platform and makes it switch direction when it hits an ObjectMovablePlatformCollider. */
	@Override public void performStepAction(World world) {
		super.performStepAction(world);
		for (WorldObject other : world.getObjects()) {
			if (other instanceof ObjectMovablePlatformCollider && collision(other)) {
				setHorizontalSpeed(((ObjectMovablePlatformCollider) other).getHorizontalSpeed());
				setVerticalSpeed(((ObjectMovablePlatformCollider) other).getVerticalSpeed());
			}
		}
	}

}
